package com.higgins.lawapp.client.settings.panels;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TabPanel;
import com.higgins.lawapp.client.listeners.DataSourceDTOListBoxListener;
import com.higgins.lawapp.client.settings.components.DataSourceDeleteButton;
import com.higgins.lawapp.client.settings.components.DataSourceExecuteCheckBox;
import com.higgins.lawapp.client.settings.components.DataSourceListBox;
import com.higgins.lawapp.client.settings.dataModel.DataSourceDTO;
import com.higgins.lawapp.client.settings.model.DataSourceModel;
import com.higgins.lawapp.client.settings.presenter.DataSourcePresenter;


public class SettingsTabPanel extends DockLayoutPanel implements DataSourceDTOListBoxListener	{
	private DataSourceDeleteButton dataSourceDeleteButton;
	private	DataSourceExecuteCheckBox dataSourceExecuteCheckBox;
	private DataSourceListBox dataSourceListBox;
	private LayoutPanel panelForListBox;
	private DataSourceModel dataSourceModel = new DataSourceModel();
	private DataSourcePresenter dataSourcePresenter = new DataSourcePresenter(dataSourceModel);
	public SettingsTabPanel()	{
		super(Unit.EM);
		setHeight("1200px");
		setWidth("800px");
		panelForListBox = new LayoutPanel();
	    panelForListBox.setHeight("30px");
	    panelForListBox.setWidth("800px");
	    addNorth(panelForListBox, 2);
		
		dataSourceListBox = new DataSourceListBox(dataSourcePresenter); 
		addDataSourceListBox(dataSourceListBox);
		
		dataSourceExecuteCheckBox = new DataSourceExecuteCheckBox(dataSourceModel);
		addDataSourceExecuteCheckBox(dataSourceExecuteCheckBox);
		
		dataSourceDeleteButton = new DataSourceDeleteButton(dataSourceModel);
		addDataSourceDeleteButton(dataSourceDeleteButton);

		SettingsInternalTabs settingsInternalTabs = new SettingsInternalTabs();
		addSettingsTabs(settingsInternalTabs);
		dataSourceListBox.addDataSourceListBoxListener(settingsInternalTabs);
		dataSourceListBox.addDataSourceListBoxListener(dataSourceModel);
		dataSourceListBox.addDataSourceListBoxListener(this);
		settingsInternalTabs.setDataSourceDTOSelected(null, 0);
		settingsInternalTabs.setHeight("600px");
		settingsInternalTabs.setWidth("800px");

	}
	public void addDataSourceListBox(DataSourceListBox dataSourceListBox)	{
		panelForListBox.add(dataSourceListBox);
	    panelForListBox.setWidgetLeftWidth(dataSourceListBox, 0, Unit.PCT, 70, Unit.PCT);
    }
	public void addDataSourceExecuteCheckBox(DataSourceExecuteCheckBox dataSourceExecuteCheckBox)	{
		panelForListBox.add(dataSourceExecuteCheckBox);
		panelForListBox.setWidgetLeftWidth(dataSourceExecuteCheckBox, 70, Unit.PCT, 20, Unit.PCT);
    }
	public void addDataSourceDeleteButton(DataSourceDeleteButton dataSourceDeleteButton)	{
		panelForListBox.add(dataSourceDeleteButton);
		panelForListBox.setWidgetRightWidth(dataSourceDeleteButton, 0, Unit.PCT, 10, Unit.PCT);
	}
	public void addSettingsTabs(TabPanel settingsTabs)	{
	    addNorth(settingsTabs, 40);
		setHeight("600px");
		setWidth("800px");	    
    }
	@Override
	public void setDataSourceDTOSelected(DataSourceDTO dataSourceDTO,
			int DataSourceIndex) {
		Boolean execute = dataSourceDTO.getDataSourceExecute();
		if (execute==null)
			execute = false;
		dataSourceExecuteCheckBox.setValue(execute);
	}
}
